﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace USERS.CYT369.COM.DAL.DbContexts
{
    public partial class CYT369BaseContext: Microsoft.EntityFrameworkCore.DbContext
    {
        private USERS.CYT369.COM.UTILITY.Connection m_Connection;
        public CYT369BaseContext()
        {
            m_Connection = USERS.CYT369.COM.UTILITY.SystemSettingService.Instance.BaseDB;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (m_Connection != null)
            {
                if (m_Connection.DBType == USERS.CYT369.COM.UTILITY.ConstStringClass.SQLSERVER2008 ||
                    m_Connection.DBType == USERS.CYT369.COM.UTILITY.ConstStringClass.SQLSERVER2005)
                {
                    optionsBuilder.UseSqlServer(m_Connection.ConnectionString).ReplaceService<Microsoft.EntityFrameworkCore.Query.IQueryTranslationPostprocessorFactory, Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServer2008QueryTranslationPostprocessorFactory>();
                }
                else
                {
                    optionsBuilder.UseSqlServer(m_Connection.ConnectionString);
                }
            }
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            string schema = null;
            if (m_Connection != null)
            {
                schema = m_Connection.DBSchema;
            }

            DocModelCreating(builder, schema);
        }

        private void DocModelCreating(ModelBuilder modelBuilder, string schema)
        {

        }

    }
}
